// pages/my/my.ts
import { getUserInfo } from '../../http/api/userServiceApi'

const tokenMixin = require('../../mixin/tokenMixin')
const app = getApp()
Page({
    behaviors: [tokenMixin],
    /**
     * 页面的初始数据
     */
    data: {
        isLogin: false,
        url: '',
        username: '未登录',
        userInfo: {}
    },

    call(e: any) {
        console.log(e.currentTarget.dataset.phone)
        wx.makePhoneCall({
            phoneNumber: e.currentTarget.dataset.phone //仅为示例，并非真实的电话号码
        })
    },

    toUpdateUser() {
        app.globalData.userInfo = this.data.userInfo
        wx.navigateTo({
            url: `/pages/user/userUpdate/userUpdate`
        })
    },

    login() {
        wx.navigateTo({
            url: '/pages/my/login/login'
        })
    },

    toMyLocation() {
        wx.navigateTo({
            url: '/pages/my/myLocation/myLocation'
        })
    },

    toPreferentialCenter() {
        wx.navigateTo({
            url: '/pages/my/preferentialCenter/preferentialCenter'
        })
    },

    toTaxiRecord() {
        wx.navigateTo({
            url: '/pages/my/taxiRecord/taxiRecord?type=0'
        })
    },
    DelLogin() {
        wx.removeStorageSync('openid')
        wx.removeStorageSync('token')
        wx.setStorageSync('user-type', 1)
        wx.redirectTo({
            url: '/pages/my/login/login'
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */ onLoad() {},

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {},

    /**
     * 生命周期函数--监听页面显示
     */ async onShow() {
        const token = wx.getStorageSync('token')
        if (token) {
            this.setData({
                isLogin: true
            })
            const res: any = await getUserInfo()
            const userInfo = res.data.data[0]
            console.log(userInfo, '---用户信息')
            this.setData({
                username: userInfo.user_sname,
                url: userInfo.user_icon,
                userInfo
            })
        }
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {},

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {},

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {},

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {},

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {}
})
